package net.hg.service.impl;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import net.hg.dao.FirstDtDao;
import net.hg.dao.SecDtDao;
import net.hg.entity.FirstDt;
import net.hg.service.FirstDtService;
import net.hg.vo.FirstDtMenuListVo;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * 一级菜单(FirstDt)表服务实现类
 *
 * @author chenrui
 * @since 2024-03-03 22:04:57
 */
@Service
public class FirstDtServiceImpl implements FirstDtService {
    @Autowired
    private FirstDtDao firstDtDao;
    @Autowired
    private SecDtDao secDtDao;

    @Override
    public List<FirstDtMenuListVo> getMenuList() {
        List<FirstDtMenuListVo> list = new ArrayList();
        QueryWrapper queryWrapper = new QueryWrapper();
        queryWrapper.orderByAsc("sort");
        List<FirstDt> firstDtList = firstDtDao.selectList(queryWrapper);
        if (firstDtList == null || firstDtList.size() <= 0){
            return null;
        }
        for (FirstDt firstDt : firstDtList) {
            FirstDtMenuListVo vo = new FirstDtMenuListVo();
            QueryWrapper queryWrapper1 = new QueryWrapper();
            queryWrapper1.orderByAsc("sort");
            queryWrapper1.eq("first_dt_id", firstDt.getId());
            BeanUtils.copyProperties(firstDt, vo);
            List secList = secDtDao.selectList(queryWrapper1);
            vo.setSecList(secList);
            list.add(vo);
        }
        return list;
    }

    @Override
    public int addFirstDt(FirstDt firstDt) {
        int i = firstDtDao.insert(firstDt);
        return i;
    }
}

